Integration

In this lesson, we will learn about definite and indefinite integrals of single and multiple integrations.

Integration is one of the two main operations of calculus, with its inverse operation, differentiation, being the other. Given a function ff of a real variable xx and an interval [a,b][a, b] of the real line, the definite integral is denoted as:

abf(x) dx\int_{a}^{b} f(x) \space dx

Integrals are calculated with the integrate() function. SymPy implements a combination of the Risch algorithm and an algorithm for computing integrals based on Meijer G-functions. These allow SymPy to compute a wide variety of indefinite and definite integrals.

Indefinite integrals#

Integration uses syntax similar to differentiation. For the indefinite integral, we specify the function and the variable with respect to which the integration is performed.

integrate(y, x)

The integrate() function does not add the constant of integration in the indefinite integral.

Let’s see an example of integrating a polynomial below:

SymPy allows for a range of integrals. Let’s see them one by one

Rational

x2x+1dx\int\frac{x^2}{x+1}dx

Trigonometric

sin2x+cos2x dx\int sin^2x +cos2x \space dx

Logarithmic and Exponential

(x2ex+1x) dx\int (x^2e^x +\frac{1}{x})\space dx

Definite integral#

Definite integrals can be computed by providing a tuple having the variable of integration, and the limits of integration:

integrate(y, (x, lowerBound, upperBound))

02x2exdx\int_{0}^{2} x^2e^x dx

For improper integrals, we use the oo symbol for infinite.

Proper Integral

Let’s look at its implementation in SymPy:

Improper Integral

0(1+2x)exdx\int_{0}^{\infty} (1+2x)e^{-x} dx

Let’s see its implementation in SymPy:

Multiple integrals#

Multiple integrals are essential when dealing with vector calculus and are a stepping stone for solving many 2-D and 3-D problems in science.

x2yz3 dxdydz\int \int \int x^2yz^3\space dxdydz

Multiple integrals can be performed by specifying several variables when the integration is performed.

Indefinite Integrals

For indefinite integrals, we use the following syntax:

integrate(f(x, y, z), x, y, z)

In the given code, the function would be integrated over x, first, then over y, then over z.

Definite Integrals

223304x2yz3 dxdydz\int_{-2}^{2} \int_{-3}^{3} \int_{0}^{4} x^2yz^3\space dxdydz

For definite integrals, we usually use tuples (we could also use lists) for providing limits of integration:

integrate(f(x, y, z), (x, lower_x, upper_x), (y, lower_y, upper_y), (z, lower_z, upper_z))

Let’s see it’s implementation below:


Let’s learn about limits in the next lesson.

Differentiation

Limits